clearvars -except Globaloption option

fID = fopen(['../../results/tables_main/US/pre1946/Table_us_break_preWWII_twoVAR_WAR.tex'], 'w');
breakyear = 1860;
load (['MAT/benchmark_US_pre', num2str(breakyear), '.mat'])
startdatenum = 1793;
enddatenum = 1860;
date = [startdatenum:1:enddatenum];
gdebt = gdebt(2:end);
surplusgdp = taxrevgdp - spendgdp;

% 1793-1799 french revolution (FR)
mask = find(date >= 1793 & date <= 1799);
fprintf(fID, '\\newcommand{\\preWWIIFRpct}{%4.2f}\n', 100 * mean(surplusgdp(mask)));
pdxpvs = exp(pxbar) .* taxrevgdp' - exp(pxbar) .* spendgdp';
fprintf(fID, '\\newcommand{\\preWWIIFRpdxpvs}{%4.2f}\n', 100 * mean(pdxpvs(mask)));
pdxCFpvs = exp(pxbar + CFT) .* taxrevgdp' - exp(pxbar + CFG) .* spendgdp';
fprintf(fID, '\\newcommand{\\preWWIIFRpdxCFpvs}{%4.2f}\n', 100 * mean(pdxCFpvs(mask)));
fprintf(fID, '\\newcommand{\\preWWIIFRpvs}{%4.2f}\n', 100 * mean(s(mask)));
fprintf(fID, '\\newcommand{\\preWWIIFRdebtgdp}{%4.2f}\n', 100 * mean(gdebt(mask)));

% 1812-1815 American War (AW)
mask = find(date >= 1812 & date <= 1815);
fprintf(fID, '\\newcommand{\\preWWIIAWpct}{%4.2f}\n', 100 * mean(surplusgdp(mask)));
fprintf(fID, '\\newcommand{\\preWWIIAWpdxpvs}{%4.2f}\n', 100 * mean(pdxpvs(mask)));
fprintf(fID, '\\newcommand{\\preWWIIAWpdxCFpvs}{%4.2f}\n', 100 * mean(pdxCFpvs(mask)));
fprintf(fID, '\\newcommand{\\preWWIIAWpvs}{%4.2f}\n', 100 * mean(s(mask)));
fprintf(fID, '\\newcommand{\\preWWIIAWdebtgdp}{%4.2f}\n', 100 * mean(gdebt(mask)));

% 1860-1864 Civil War (CW)
breakyear = 1860;
load (['MAT/benchmark_US_post', num2str(breakyear), '.mat'])

startdatenum = breakyear + 1;
enddatenum = 1946;
date = [startdatenum:1:enddatenum];
surplusgdp = taxrevgdp - spendgdp;
gdebt = gdebt(2:end);
pdxpvs = exp(pxbar) .* taxrevgdp' - exp(pxbar) .* spendgdp';
pdxCFpvs = exp(pxbar + CFT) .* taxrevgdp' - exp(pxbar + CFG) .* spendgdp';
mask = find(date >= 1861 & date <= 1865);
fprintf(fID, '\\newcommand{\\preWWIICWpct}{%4.2f}\n', 100 * mean(surplusgdp(mask)));
fprintf(fID, '\\newcommand{\\preWWIICWpdxpvs}{%4.2f}\n', 100 * mean(pdxpvs(mask)));
fprintf(fID, '\\newcommand{\\preWWIICWpdxCFpvs}{%4.2f}\n', 100 * mean(pdxCFpvs(mask)));
fprintf(fID, '\\newcommand{\\preWWIICWpvs}{%4.2f}\n', 100 * mean(s(mask)));
fprintf(fID, '\\newcommand{\\preWWIICWdebtgdp}{%4.2f}\n', 100 * mean(gdebt(mask)));

fclose(fID);
